package controller
{
import core.Context;

import model.events.LoginEvent;

import view.LoginWindow;
/**
 * @author daichangxin
 */
public class LoginWindowController implements ILoginWindowController
{
	private var _loginWindow:LoginWindow;
	
	public function LoginWindowController()
	{
		Context.userModel.addEventListener(LoginEvent.SUCCESS, onLoginSuccess);
		Context.userModel.addEventListener(LoginEvent.FAIL, onLoginFail);
	}
	
	public function createUI():void
	{
		_loginWindow = new LoginWindow(this);
	}
	
	public function onLoginButtonClick() : void
	{
		var userName:String = _loginWindow.inputUserName;
		var password:String = _loginWindow.inputPassword;
		
		Context.userModel.login(userName, password);
	}
	
	public function get loginWindow():LoginWindow
	{
		return _loginWindow;
	}

	private function onLoginFail(event : LoginEvent) : void
	{
		_loginWindow.showLoginFail();
	}
	
	private function onLoginSuccess(e:LoginEvent):void
	{
		_loginWindow.showLoginSuccess();
	}
}
}
